#ifndef QPROPERTYFACTORY_H
#define QPROPERTYFACTORY_H

#include "sharedlibglobal.h"

#include <QMetaObject>
#include <QMap>
#include <QString>
#include <QWidget>
#include <QUndoStack>

class QAbstractProperty;

struct tagPropertyInfo
{
    const QMetaObject *m_property_meta_object;
    const QMetaObject *m_editor_meta_object;
};

class SHAREDLIB_EXPORT QPropertyFactory
{
public:
    QPropertyFactory(const QString &name,const QMetaObject* object,int type);

public:
    static void register_property(const QString &name,const QMetaObject* property);
    static void register_editor(const QString &name,const QMetaObject* editor);
    static QAbstractProperty* create_property(const QString& name);
    static QWidget*           create_editor(const QString& name,QAbstractProperty* property,QUndoStack* stack=NULL);
protected:
    static QMap<QString,tagPropertyInfo*>        *m_meta_map;
};

#ifndef qRegisterProperty
    #define qRegisterProperty(type) \
        QPropertyFactory factory_property_##type(type::get_property_name(),&type::staticMetaObject,1);
#endif

#ifndef qRegisterPropertyEditor
    #define qRegisterPropertyEditor(name,type) \
                QPropertyFactory factory_editor_##name(#name,&type::staticMetaObject,2);
#endif

#endif // QPROPERTYFACTORY_H
